package com.kaishengit.dao;


import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.kaishengit.pojo.User;


@Repository
public class UserDao extends BaseDao<User,Integer> {
	
	public User findName(User user) {
		String hql = "from User where username = ?";
		Query query = getSession().createQuery(hql);
		query.setParameter(0, user.getUsername());
		return (User) query.uniqueResult();
	}
	
	public User findNameAndPassword(User user) {
		String hql = "from User where username = ? and password = ?";
		Query query = getSession().createQuery(hql);
		query.setParameter(0, user.getUsername());
		query.setParameter(1, user.getPassword());
		return (User) query.uniqueResult();
	}

	public User findName(String name) {
		String hql = "from User where username = ?";
		Query query = getSession().createQuery(hql);
		query.setParameter(0, name);
		return (User) query.uniqueResult();
	}

	public User findByName(String name) {
		String hql = "from User where username = ?";
		Query query = getSession().createQuery(hql);
		query.setParameter(0, name);
		return (User) query.uniqueResult();
	}

}
